<template>
  <div class="flexContent">
    <div class="searchBox">
      <el-form ref="formRef" @submit.native.prevent class="demo-form-inline" label-position="left" label-width="auto">
        <div class="serFlexBox">
          <div class="inputBox">
            <el-row :gutter="12" style="display: flex;flex-wrap: wrap;">
              <el-col :xs="12" :sm="12" :md="12" :lg="8" :xl="6">
                <el-form-item label="暂无">
                  <el-input v-model="msgName" style="width: 95%;" placeholder="请输入..." />
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div class="btnBox">
            <el-button class="searchBtn" icon="el-icon-search">搜索</el-button>
            <el-button class="resetBtn" icon="el-icon-refresh-right">重置</el-button>
          </div>
        </div>
      </el-form>
    </div>
    <div class="add">
      <el-button class="addBtn" @click="addFn">新增</el-button>
    </div>
    <div class="table" id="tableBox" v-height>
      <div style="flex:1;">
        <vxe-table :column-config="{ resizable: true }" class="tablebox" border ref="xTable1"
          :row-config="{ isHover: true }" :scroll-y="{ enabled: true, gt: 21 }" style="width: 100%" height="100%"
          align="center">
          <vxe-column type="seq" title="序号" width="80"></vxe-column>
          <vxe-column field="version" title="版本号" />
          <vxe-column field="updateUrl" title="更新链接" />
          <vxe-column field="appType" title="APP类型">
            <template v-slot="{ row }">
              <span v-if="row.appType == '0'">收银app</span>
              <span v-if="row.appType == '1'">称重app</span>
              <span v-if="row.appType == '2'">PDA</span>
              <span v-if="row.appType == '3'">门店助手</span>
            </template>
          </vxe-column>
          <vxe-column field="isForce" title="是否强制更新">
            <template v-slot="{ row }">
              <span>{{ row.isForce === '0' ? '否' : '是' }}</span>
            </template>
          </vxe-column>
          <vxe-column field="updateName" title="更新人" />
          <vxe-column field="updateTime" sortable title="更新时间">
            <template v-slot="{ row }">
              {{ row.updateTime | parseTime }}
            </template>
          </vxe-column>
          <vxe-column title="操作" fixed="right" width="150">
            <template v-slot="{ row }">
              <el-button type="text" size="big" style="margin-right: 10px;color: black;"
                @click.stop="getDetail(row.content)">版本信息</el-button>
              <el-button type="text" size="big" style="margin-right: 10px;color: red;"
                @click="$delFn('版本', del, row)">删除</el-button>
            </template>
          </vxe-column>
        </vxe-table>
      </div>
      <div class="paginationBox">
        <el-pagination :current-page="page.pageNum" background :page-sizes="$pageSizes" :page-size="page.pageSize"
          layout="total,->, sizes, prev, pager, next, jumper" :total="page.total" @size-change="handleSizeChange"
          @current-change="handleCurrentChange" />
      </div>
    </div>
    <el-dialog title="版本信息" :visible.sync="showDialog" width="30%" center>
      <span>{{ content }}</span>
    </el-dialog>
  </div>
</template>

<script>
import { getAppList, delApp } from '@/api/h5'
import dayjs from 'dayjs'
export default {
  name: 'ApkInfo',
  filters: {
    parseTime(time) {
      return dayjs(time).format('YYYY-MM-DD HH:mm:ss')
    }
  },
  data() {
    return {
      showDialog: false,
      msgName: '',
      content: '',
      page: {
        pageNum: 1,
        pageSize: 20,
        total: 0
      },
      appList: []
    }
  },
  created() {
    this.getAPPList()
  },
  methods: {
    async getAPPList() {
      const res = await getAppList(this.page)
      if (res.code === 200) {
        console.log(res)
        const result = res.data
        this.appList = result.list
        this.page.pageSize = result.pageSize
        this.page.pageNum = result.pageNum
        this.page.total = result.total
        console.log('appList', this.appList)
        const $table = this.$refs.xTable1
        $table.loadData(this.appList);
      } else {
        // this.$message.error(res.message)
      }
    },
    addFn() {
      this.$router.push('apkAdd')
    },
    async del(row) {
      const res = await delApp({ id: row.id })
      // console.log(res)
      if (res.code === 200) {
        this.$message.success('删除成功')
        if (this.appList.length === 1 && this.page.pageNum > 1) this.page.pageNum--
        this.getAPPList()
      } else {
        // this.$message.error(res.message)
      }
    },
    // 获取条数改变
    handleSizeChange(val) {
      this.page.pageSize = val
      this.page.pageNum = 1
      // console.log(`每页 ${val} 条`)
      this.getAPPList()
    },
    // 获取页数改变
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`)
      this.page.pageNum = val
      this.getAPPList()
    },
    close() {
      this.showDialog = false
      this.content = ''
    },
    getDetail(val) {
      this.showDialog = true
      this.content = val
    }
  }
}
</script>

<style lang="scss" scoped></style>
